import utils from '../../utils/utils';

var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    list: [
      {
        name: '添加周记',
        path: '/pages/editWeek/editWeek',
        icon: '/images/文档_1.png'
      }, {
        name: '添加月记',
        path: '/pages/editMonth/editMonth',
        icon: '/images/文档.png'
      }, {
        name: '查看周记',
        path: '/pages/showWeek/showWeek',
        icon: '/images/weeklyview.png'
      }, {
        name: '查看月记',
        path: '/pages/showMonth/showMonth',
        icon: '/images/monthlyview.png'
      }, {
        name: '导出日记',
        path: '/pages/export/export',
        icon: '/images/导出.png'
      }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("进入用户页");
    var that = this;
    wx.getUserInfo({
      success: function(res) {
        that.setData({
          userInfo: res.userInfo
        });
      }
    });
  },

  navigate: function (event) {
    console.log(event.currentTarget);
    if (event.currentTarget.id == '/pages/editWeek/editWeek') {
      console.log(new Date().getDay());
      if (new Date().getDay() != 1) {
        wx.showModal({
          title: '提示',
          content: '今天不是周一哦，请周一再来~',
          showCancel: false,
          success: function(resp) {
            if (resp.confirm) {
              console.log('用户点击确定')
            }
          }
        });
      } else {
        wx.navigateTo({
          url: event.currentTarget.id
        });
      }
      // wx.navigateTo({
      //   url: event.currentTarget.id
      // });

    } else if (event.currentTarget.id == '/pages/editMonth/editMonth') {
      console.log(new Date().getDate(),utils.getCurrentMonthLast().getDate());
      if (new Date().getDate() != utils.getCurrentMonthLast().getDate()) {
        wx.showModal({
          title: '提示',
          content: '今天不是月底哦，请月底再来~',
          showCancel: false,
          success: function(resp) {
            if (resp.confirm) {
              console.log('用户点击确定')
            }
          }
        });

      } else {
         wx.navigateTo({
          url: event.currentTarget.id
        });       
      }
      // wx.navigateTo({
      //   url: event.currentTarget.id
      // });       

    } else {
      wx.navigateTo({
        url: event.currentTarget.id
      });
    }

  }


})